package com.timothy.junk.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.sina.util.StringUtil;
import com.timothy.junk.R;
import com.timothy.junk.cbond.bean.CBondResult;

import java.util.HashMap;
import java.util.List;

public class CBondAdaptor extends BaseAdapter {
	private Context 					mContext;
	private List<CBondResult> 		listItems;
	private LayoutInflater 				mInflater;

	HashMap<Integer,View> viewMap = new HashMap<Integer,View>();

	static class ViewHolder{
		public TextView cBondIndex;
        public TextView cBondName;
        public TextView cBondPrice;
	    public TextView cBondValue;
	    public TextView cBondDiscount;
	 }

	public CBondAdaptor(Context context, List<CBondResult> data) {
		this.mContext = context;
		mInflater = LayoutInflater.from(context); 
		this.listItems = data;
	}

	
	@Override
	public int getCount() {
		return listItems.size();
	}

	@Override
	public Object getItem(int arg0) {
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder holder;  
        if (convertView == null){  
            holder = new ViewHolder();  
            convertView = mInflater.inflate(R.layout.cbond_list_item, null);
            
            holder.cBondIndex = (TextView) convertView.findViewById(R.id.cBondIndex);
			holder.cBondName = (TextView) convertView.findViewById(R.id.cBondName);
			holder.cBondPrice = (TextView) convertView.findViewById(R.id.cBondPrice);
			holder.cBondValue = (TextView) convertView.findViewById(R.id.cBondValue);
			holder.cBondDiscount = (TextView) convertView.findViewById(R.id.cBondDiscount);
			
            convertView.setTag(holder);  
        }else {  
            holder = (ViewHolder) convertView.getTag();  
        }

        CBondResult bean = listItems.get(position);
		holder.cBondIndex.setText(String.valueOf(position+1));
		holder.cBondName.setText(bean.getcBondName());
		holder.cBondPrice.setText(StringUtil.formatData2Deci(bean.getcBondPrice()));
		holder.cBondValue.setText(StringUtil.formatData2Deci(bean.getcBondValue()));
		holder.cBondDiscount.setText(StringUtil.formatData2Deci(bean.getDiscount()*100)+"%");

        return convertView; 
        
	}

}
